
class Singleton1 {
    //饿汉式
    public static Singleton1 instance = new Singleton1();

    private Singleton1(){

    }

    public Singleton1 getInstance(){
        return instance;
    }
}
//懒汉式
public class Singleton{
    public static Singleton instance;

    private Singleton getInstance(){
        if(instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}
